package cn.x.utils;

import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Base64;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
/**
 * @author a tester
 * @date 2021/5/16
 */
public class RandomName {

    private static String[] firstNameArr = "欧阳,太史,上官,司马,东方,独孤,南宫,夏侯,诸葛,尉迟,公羊,赫连,皇甫,公孙,慕容,钟离,长孙,宇文,司徒,鲜于,司空,拓跋,轩辕,令狐,百里,呼延,东郭,西门,王,李,张,刘,陈,杨,黄,赵,吴,周,徐,孙,马,朱,胡,郭,何,林,罗,高,郑,梁,谢,宋,唐,许,韩,邓,冯,曹,彭,曾,肖,田,董,潘,袁,蔡,蒋,余,于,杜,叶,程,魏,苏,吕,丁,任,卢,姚,沈,钟,姜,崔,谭,陆,范,汪,廖,石,金,韦,贾,夏,付,方,邹,熊,白,孟,秦,邱,侯,江,尹,薛,闫,段,雷,龙,黎,史,陶,贺,毛,郝,顾,龚,邵,万,覃,武,钱,戴,严,莫,孔,向,常".split(",");

    private static String[] secondNameArr = "嘉欣,佳欣,嘉怡,佳怡,嘉仪,佳琪,嘉琪,家琪,俊杰,俊豪,嘉豪,刚,强,伟,健,雄,壮,红,彤,霞,艳,丽,美,雪梅,诗雨,诗语,若兮,子轩,晓玲,晓琳,欣怡,辰皓,家铭,静怡,亮,敏,建国,建军,浩轩,博,小红,小明,小军,瑛,旭,磊,爱梅,志芳,光,隽仙,燕青,振杰,卫东,红宇,福平,敬伟,增志,志威,金起,云庆,全福,建立,连水,智胜,春利,鹏,喜茂,会英,连军,凤琴,艳萍,龙,红丽,莹,淑敏,建章,丽芬,伟旺,冬梅,银祥,志辉,振山,然欣,卫民,娟,集合,蕾,英才,宗清,莉,国栋,少斌,晶,谦,占海,百春,雪雯,红月,蓓,培红,献英,子坤,柯瑶,丹,颖,艳茹,金柱,艳惠,丽静,玉良,红莲,泽,琳,亚娟,保江,红梅,巍,树江,林红,迎春,青青,尚,艳丽,志勇,岩红,博涛,冲,胜利,继忠,静,玲,德林,晓丽,玉英,淑媛,青,燕飞,和平,素娟,江涛,玉红,煜,荣基,春龙,策,峰,娜,锐坚,艳玲,华丽,辉,梅,丽萍,春红,秋莲,春恒,卫国,春兰,净微,豫,二光,建学,艳薇,恒卫,来胜,晓东".split(",");
    public static String getRandomName(String fistName,String secondName){
        if(StringUtils.isBlank(fistName)){
            fistName = firstNameArr[ThreadLocalRandom.current().nextInt(firstNameArr.length)];
        }
        if(StringUtils.isBlank(secondName)){
            secondName = secondNameArr[ThreadLocalRandom.current().nextInt(secondNameArr.length)];
        }
        return fistName + secondName;
    }

    public static void main(String[] args) throws Exception {
        String names ="宋爱梅,王志芳,于光,贾隽仙,贾燕青,刘振杰,郭卫东,崔红宇,马福平,冯红,崔敬伟,穆增志,谢志威,吕金起,韩云庆,鲁全福,郭建立,郝连水,闫智胜,魏春利,刘鹏,张喜茂,李会英,路连军,靖凤琴,李艳萍,马龙,顾红丽,马莹,贾淑敏,杜建章,朱丽芬,刘伟旺,张冬梅,王银祥,张志辉,王振山,刘然欣,张卫民,张丽,孙娟,范艳,王集合,戴蕾,杨英才,闫宗清,马莉,张国栋,刘少斌,张晶,于谦,高占海,李百春,袁雪雯,要红月,杨蓓,张培红,侯献英,李子坤,李柯瑶,李丹,田颖,刘艳茹,杨金柱,曹淑敏,彭艳惠,刘娟,甄丽静,杨玉良,谭红莲,张泽,张琳,周亚娟,杨保江,魏红梅,王巍,刘树江,王林红,李迎春,申青青,李尚,许艳丽,曹志勇,王岩红,邓博涛,张冲,蒋胜利,申继忠,孙静,张玲,王德林,杨晓丽,高巍,王玉英,李淑媛,李磊,段青,马燕飞,张和平,王素娟,门江涛,王玉红,王煜,杜荣基,苏春龙,张策,王峰,李健,石娜,袁锐坚,刘艳玲,张伟,杨华丽,周辉,韩梅,邓莉,李丽萍,王春红,张静,刘秋莲,冯春恒,王卫国,常春兰,刘净微,乔豫,刘二光,张建学,刘艳薇,马恒卫,闫来胜,郭晓东,张辉";
        String[] namesArr = names.split(",");
        String[] finalNameArr = Arrays.stream(namesArr).map(e -> e.substring(1,e.length())).toArray(String[]::new);
        System.out.println(Arrays.toString(finalNameArr));

        System.out.println(secondNameArr.length);
        System.out.println(Arrays.toString(secondNameArr));
        //去重
        String[] commonSecondNameArr2 = Arrays.stream(secondNameArr).distinct().toArray(String[]::new);
        System.out.println(commonSecondNameArr2.length);
        System.out.println(Arrays.toString(commonSecondNameArr2));

        System.out.println(Arrays.stream(secondNameArr).collect(Collectors.joining(",")));
        System.out.println(Arrays.stream(secondNameArr).distinct().collect(Collectors.joining(",")));

        for(int i=0;i<100;i++){
            System.out.println(getRandomName("",""));
        }

        FileInputStream fi = new FileInputStream("img/ABankCardNo.png");
        byte[] imgByteArray = new byte[fi.available()];
        fi.read(imgByteArray);
        fi.close();
        System.out.println(imgByteArray);
        System.out.println(Arrays.toString(imgByteArray));
        String imgBase64Str = Base64.getEncoder().encodeToString(imgByteArray);
        System.out.println(imgBase64Str);
        String imgStr = "";
    }
}
